I solved the “getaddrinfo ENOTFOUND xxx.region.amazonaws.com” error
Hi, this is Charu from Games Solution Department, Classmethod.
I am writing this blog to tell the solution for the error "getaddrinfo ENOTFOUND xxx.region.amazonaws.com". I got this error when I was running the lambda function written in TypeScript language.
The Original Code:
The original code which I was trying to run-
import { DynamoDBClient, paginateScan } from "@aws-sdk/client-dynamodb"; import { unmarshall } from "@aws-sdk/util-dynamodb"; const TABLE_NAME = process.env.TABLE_NAME || ""; interface Employee { user_id_name: string; } const client = new DynamoDBClient({ region: "ap-northaest-1", }); const paginatorConfig = { client: client, }; export const handler = async () => { let employees: Employee[] = []; const params = { TableName: TABLE_NAME }; const paginator = paginateScan(paginatorConfig, params); for await (const page of paginator) { if (page.Items) { employees.push( ...page.Items.map((item) => { return unmarshall(item) as Employee; }) ); } } return { statusCode: 200, }; };
This code is to scan the items from the dynamoDB table.
The code looked fine to me but I got the following error-
The Mistake:
If you look closely, there is a mistake in the AWS region spelling-
const client = new DynamoDBClient({ region: "ap-northaest-1", });
The actual code snippet should be like this-
const client = new DynamoDBClient({ region: "ap-northeast-1", });
Conclusion:
The ENOTFOUND error can happen when the system couldn't resolve the domain name you provided. There can be other reasons too, such as:
I hope your error is resolved.
Thank you for reading!
Happy Learning :)